package iterator;

import java.util.ArrayList;

/**
 * <p>Title BookShelf</p>
 *
 * @author YiMing Liu
 * @date 2018/6/7 15:58
 * <p>Description:书架</p>
 */
public class BookShelf implements Aggregate {

    private ArrayList books;
    private int last=0;

    public BookShelf(int maxsize) {
        this.books =  new ArrayList(maxsize);
    }

    /**
     * 返回当前索引的元素
     * @param index
     * @return
     */
    public Book getBookAt(int index) {
        return (Book) books.get(index);

    }

    /**
     * 添加一个元素
     * @param book
     */
    public void appendBook(Book book){
        books.add(book);
    }

    /**
     * 获得数组或者集合的长度
     * @return
     */
    public int getLength(){return books.size();}

    /**
     * 创建迭代器的具体实现
     * @return
     */
    @Override
    public Iterator createIterator() {
        return new BookkShelfIterator(this);
    }
}
